import http from '@/utils/http'

const BASE_URL = '/settlement/earnings'

/** 结算统计图表通用总览类型 */
export interface SettlementDashboardOverviewCommonResp {
    total: number
    today: number
    growth: number
    dataList: SettlementDashboardChartCommonResp[]
}

/** 结算统计图表通用图表类型 */
export interface SettlementDashboardChartCommonResp {
    name: string
    value: number
}

/**
 * 根据员工ID查询员工未结算总览
 * @param {string} id ID
 * @returns
 */
export function getOverviewSettlementYearByUserIdNotSettled(id: string) {
    return http.get<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/year/not/settled/${id}`);
}

/**
 * 获取员工收益（未结算） - 以及已经获得的收益（已经结算）
 * @returns
 */
export function getNotSettledMoney() {
    return http.get<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/settled`);
}

/**
 * 获取所有员工已结算的收益
 * @returns
 */
export function getAllSettledEarnings() {
    return http.get<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/all/settled`);
}

/**
 * 获取所有员工未结算的收益
 * @returns
 */
export function getAllSettledNotEarnings() {
    return http.get<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/all/not/settled`);
}

/**
 * 提现申请
 * @returns
 */
export function WithdrawalRequests() {
    return http.get(`${BASE_URL}/withdrawal/requests`);
}

/**
 * 根据员工ID查询员工已结算总览
 * @param {string} id ID
 * @returns
 */
export function getOverviewSettlementYearByUserIdSettled(id: string) {
    return http.get<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/year/settled/${id}`);
}

/**
 * 根据员工ID查询员工各个渠道总览
 * @param {string} id ID
 * @returns
 */
export function getOverviewSettlementChannelByUserId(id: string) {
    return http.get<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/analysis/channel/${id}`);
}

/**
 * 查询登录用户渠道数据
 * @returns
 * @param data
 */
export function getChannelEarningsTrends(data: Array<string>) {
    return http.post<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/channel/earnings/trends`, data);
}

/**
 * 查询登录用户所有月份的收益
 * @returns
 */
export function getAllMonthsEarnings() {
    return http.get<SettlementDashboardOverviewCommonResp>(`${BASE_URL}/all/month/settled`);
}

/**
 * 下载账单
 * @returns
 */
export function downloadSettlementAccount(data: Array<string>) {
    data[0] = data[0] === undefined ? null : data[0];
    data[1] = data[1] === undefined ? null : data[1];
    return http.download(`${BASE_URL}/download/account/${data[0]}/${data[1]}`);
}

